﻿using DevelopAssistant.Core.ToolBar;
using DevelopAssistant.Service;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DevelopAssistant.Core.ToolBox
{
    public partial class EditDataBaseConnection : ToolBoxBase
    {
        public EventHandler Apply { private get; set; }
        public EventHandler Cancle { private get; set; }

        public EditDataBaseConnection()
        {
            InitializeComponent();
            InitializeControls();
        }

        private void InitializeControls()
        {
            this.panel1.TopBlackColor = Color.WhiteSmoke;
            this.panel1.BottomBlackColor = SystemColors.Control;
            this.panel1.BorderColor = this.XTheme.FormBorderOutterColor;
        }

        public EditDataBaseConnection EditDataBaseConnectiontor(DataBaseServer dbserver, LeftMenuBar menubar)
             
        {
            EditDataBaseConnection _base =new EditSqlServerConnection(dbserver,menubar);

            switch (dbserver.ProviderName)
            {
                case "System.Data.Sql":
                case "System.Data.SQL":
                    _base = new EditSqlServerConnection(dbserver, menubar);
                    break;
                case "System.Data.Sqlite":
                    _base = new EditSqliteServerConnection(dbserver, menubar);
                    break;
            }

            return _base;
        }

        private void btnCancle_Click(object sender, EventArgs e)
        {
            if (this.Cancle != null)
                this.Cancle(sender, new EventArgs());
            this.DialogResult = DialogResult.No;
        }

        protected void SetBtnApplyEnabled(bool bl)
        {
            this.btnApplyOk.Enabled = bl;
        }

        private void btnApplyOk_Click(object sender, EventArgs e)
        {
            if (this.Apply != null)
                this.Apply(sender, new EventArgs());
            this.DialogResult = DialogResult.Yes;
        }
    }
}
